import 'package:flutter/material.dart';
import 'package:startup_namer/update_item_model.dart';


class AppStoreItem extends StatelessWidget {

  final UpdateItemModel model;
  final VoidCallback onPressed;

  const AppStoreItem(this.model, this.onPressed) : super();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('App Store Item Demo'),
      ),
      body: _body(),
    );
  }

  Widget _body() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _buildTopRow(),
        _buildBottomRow(),
      ],
    );
  }

  Widget _buildTopRow() {
    return Row(
      //水平摆放
      children: <Widget>[
        Padding(
          padding: EdgeInsets.all(10),//边距均为 10
          child: ClipRRect(//圆角矩形裁切控件
            borderRadius: BorderRadius.circular(8.0),//设置圆角半径
            child: Image.asset(model.appIcon, width: 80, height: 80,),//图片控件
          ),
        ),
        Expanded(//Expanded 用来拉伸中间的区域
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,// 垂直方向对齐
              crossAxisAlignment: CrossAxisAlignment.start,//水平方向左对齐
              children: [
                Text(model.appName, maxLines: 1,),
                Text(model.appDate, maxLines: 1,),
              ],
            )
        ),
        Padding(
          padding: EdgeInsets.fromLTRB(0, 0, 10, 0),//右边距
          child: TextButton(child: Text("open"), onPressed: onPressed,),
        ),
      ],
    );
  }

  Widget _buildBottomRow() {
    return Padding(
      padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(model.appDescription),
          Padding(
            padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
            child: Text("${model.appVersion} • ${model.appSize} MB"),
          )
        ],
      ),
    );
  }

}



